﻿//Copyright © 2012 by Geodata Danmark. All Rights Reserved
//Author: Carsten Helsted

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BrowseByURL
{
    public partial class frmEditUrlExp : Form
    {
        private URLDef _urlDef = null;
        public frmEditUrlExp()
        {

            InitializeComponent();
        }
        public frmEditUrlExp(URLDef urlDef)
        {
            _urlDef = urlDef;

            InitializeComponent();

            cbBrowsers.Items.Clear();
            cbBrowsers.DataSource = Program.InstalledBrowsers;
            cbBrowsers.DisplayMember = "DisplayName";
            cbBrowsers.ValueMember = "Name";

            cbBrowsers.DropDownStyle = ComboBoxStyle.DropDownList;

            if (urlDef != null)
            {
                cbBrowsers.SelectedItem = urlDef.UseBrowser;
                txtURL.Text = urlDef.URLExp;
            }

        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (_urlDef != null)
            {
                _urlDef.UseBrowser = (Browser)cbBrowsers.SelectedItem;
                _urlDef.URLExp = txtURL.Text;
            }
            else
            {
                URLDef u = new URLDef(txtURL.Text, (Browser)cbBrowsers.SelectedItem);
                Program.UrlDefinitions.Add(u);
            }
            this.Close();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
